﻿@model Vertex
@{
    ViewData["Title"] = $"Submission s{Model.Id}: {Model.Name}";
    string error = ViewBag.Error;
}

<h2 class="mt-2">Submission s@(Model.Id): <a asp-action="SourceCode">@Model.Name</a></h2>

<div class="row">
    <div class="col-md-6 col-lg-4">
        <table class="table table-sm table-striped">
            <tr>
                <th>ID</th>
                <td>@Model.Id</td>
            </tr>
            <tr>
                <th>Description</th>
                <td>@Model.Name</td>
            </tr>
            <tr>
                <th>Upload Time</th>
                <td>@Html.CstTime(Model.UploadTime)</td>
            </tr>
            <tr>
                <th>Exclusive</th>
                <td><a asp-action="Detail" asp-route-exclusive_category="@Model.ExclusiveCategory">@Model.ExclusiveCategory</a></td>
            </tr>
            <tr>
                <th>Non-exclusive</th>
                <td><a asp-action="Detail" asp-route-inclusive_category="@Model.InclusiveCategory">@Model.InclusiveCategory</a></td>
            </tr>
            <tr>
                <th>Language</th>
                <td><a asp-action="Detail" asp-route-language="@Model.Language">@Model.Language</a></td>
            </tr>
        </table>
    </div>
</div>

@if (error == null)
{
    <style>
        .text-delete { text-decoration: line-through!important; }
    </style>

    <h3>Comparisons</h3>
    <div class="table-wrapper mt-2">
        <table class="data-table pagination-sm table table-hover table-striped table-sm" role="grid">
            <thead>
                <tr>
                    <th scope="col" class="sortable searchable">excl.</th>
                    <th scope="col" class="sortable searchable">SID</th>
                    <th scope="col" class="sortable searchable">status</th>
                    <th scope="col" class="sortable searchable">tot.</th>
                    <th scope="col" class="sortable searchable">big.</th>
                    <th scope="col" class="sortable searchable">percent</th>
                    <th scope="col" class="sortable searchable">this.</th>
                    <th scope="col" class="sortable searchable">that.</th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var cmp in Model.Comparisons)
                {
                    <tr asp-action="Compare" asp-route-rid="@cmp.Id" class="@(cmp.Justification == ReportJustification.Claimed ? "table-danger" : "")">
                        <td use-a data-order="@cmp.ExclusiveCategory">@cmp.ExclusiveCategory</td>
                        <td use-a data-order="@cmp.SubmissionIdAnother">s@(cmp.SubmissionIdAnother): @cmp.SubmissionNameAnother</td>
                        <td use-a class="text-variant">@(cmp.State == ReportState.Finished ? cmp.Justification == ReportJustification.Ignored ? "ignored" : cmp.Justification == ReportJustification.Claimed ? "marked" : "finished" : "pending")</td>
                        <td class="@(cmp.Justification == ReportJustification.Ignored ? "text-delete" : "")" use-a>@cmp.TokensMatched</td>
                        <td class="@(cmp.Justification == ReportJustification.Ignored ? "text-delete" : "")" use-a>@cmp.BiggestMatch</td>
                        <td class="@(cmp.Justification == ReportJustification.Ignored ? "text-delete" : "")" use-a data-order="@(cmp.Justification == ReportJustification.Ignored ? 0 : cmp.Percent)">@($"{cmp.Percent:F2}%")</td>
                        <td class="@(cmp.Justification == ReportJustification.Ignored ? "text-delete" : "")" use-a data-order="@(cmp.Justification == ReportJustification.Ignored ? 0 : cmp.PercentSelf)">@($"{cmp.PercentSelf:F2}%")</td>
                        <td class="@(cmp.Justification == ReportJustification.Ignored ? "text-delete" : "")" use-a data-order="@(cmp.Justification == ReportJustification.Ignored ? 0 : cmp.PercentIt)">@($"{cmp.PercentIt:F2}%")</td>
                        <td><a asp-action="SourceCode" asp-route-id="@cmp.SubmissionIdAnother"><i class="fas fa-file-code"></i></a></td>
                        <td><a asp-area="Plagiarism" asp-controller="Report" asp-action="Compare" asp-route-rid="@cmp.Id" target="_blank"><i class="fas fa-external-link-alt"></i></a></td>
                    </tr>
                }
            </tbody>
        </table>
    </div>

    <script type="text/javascript">
        $().ready(function () {
            $('.data-table').DataTable({
                "paging": true,
                "pageLength": 50,
                "searching": true,
                "ordering": true,
                "info": false,
                "order": [[5, 'desc']],
                "autoWidth": true,
                "lengthChange": true,
                "serverSide": false,
                "language": {
                    "searchPlaceholder": "filter table",
                    "search": "_INPUT_",
                    "oPaginate": {
                        "sPrevious": "&laquo;",
                        "sNext": "&raquo;",
                    },
                },
                'aoColumnDefs': [
                    { aTargets: ['sortable'], bSortable: true },
                    { aTargets: ['searchable'], bSearchable: true },
                    { aTargets: ['_all'], bSortable: false, bSearchable: false }
                ],
            });
        });
    </script>
}
else
{
    <h3>Compilation Details</h3>
    <div class="alert alert-danger">
        Compilation failed. Frontend should be updated, or this submission cannot compile simply.
        If this submission relays on macros from C++, please expand it manually then upload it as external ones.
        <a href="#" class="alert-link" data-toggle="modal" data-target="#recompileModal">Retry &raquo;</a>
    </div>
    <pre class="output_text">@error</pre>
    <form id="recompileModal" method="post" asp-action="Recompile" asp-route-sid="@Model.SetId" asp-route-id="@Model.Id" class="modal fade" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Recompile the submission</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>Are you sure to recompile this submission? Results may not change.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
                    <button type="submit" class="btn btn-danger">Yes</button>
                </div>
            </div>
        </div>
    </form>
}
